//
//  MapCityViewController.m
//  LZMPro
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 LZS. All rights reserved.
//

#import "MapCityViewController.h"
#import "CityView.h"
#import "AFNData.h"
#import "UIImage+original.h"
@interface MapCityViewController ()<CityDelegate,UIScrollViewDelegate>

@property (nonatomic, retain)CityView *city;

@property (nonatomic,retain)NSTimer *timer;

@property (nonatomic,assign) float cureentColor;

@end

@implementation MapCityViewController


-(void)dealloc
{
     self.city.scroll.delegate = nil;
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

     self.navigationController.navigationBar.translucent = YES;

  self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(changeMycolor) userInfo:nil repeats:YES];

    
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
   
    [self.timer invalidate];
    self.timer = nil;
    
}



-(void)changeMycolor
{
    
    if (self.timer == nil) return;
        
    self.cureentColor += 0.01;
    
   [[[self.navigationController.navigationBar subviews]objectAtIndex:0] setAlpha: (1.0 - self.cureentColor)];
    
    
    NSLog(@"555555%f",self.cureentColor);
    if( ABS(self.cureentColor - 1.0)<= 0.01 ) {
        
         [[[self.navigationController.navigationBar subviews]objectAtIndex:0] setAlpha: 0];
        
        [self.timer invalidate];
        self.timer = nil;

        
    }
    
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.cureentColor = 0;
 
    UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithImage:[UIImage getoraiginalImageWithName:@"add_new_poi_back_btn"] style:UIBarButtonItemStylePlain target:self action:@selector(pop)];
    self.navigationItem.leftBarButtonItem = left;
    
    self.city = [[CityView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT )];
     self.city.delegate = self;
     self.city.scroll.delegate = self;
  
      self.city.model = self.model;
    
       [self.view addSubview:self.city];
  
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    if (self.city.scroll == scrollView) {
        
        
        float offsetY = scrollView.contentOffset.y;
    
        if (offsetY < 0) {

            NSLog(@"%f",offsetY);
            self.city.headImage.height = HEIGHT *0.3 - offsetY;
            self.city.headImage.y = offsetY;
          
 
        
            
        }
        
        float bi = (offsetY + 64) /(HEIGHT*0.3);
        
        [[[self.navigationController.navigationBar subviews]objectAtIndex:0] setAlpha:bi];
        
       

        
    
        
    }
}

-(void)push_album
{
    
}

-(void)pop

{
    [self.navigationController popViewControllerAnimated:YES];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
